<template>
	<view class="page" :style="themeColor">
		<view class="flex benben-position-layout flex flex-wrap align-center platformMessage_flex_0"
			:style="{height:(64+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class='flex flex-wrap align-center justify-between flex-sub platformMessage_fd0_0'>
				<view class='flex flex-wrap align-center platformMessage_fd0_0_c0'
					@tap.stop="handleJumpDiy" data-type="back" data-url="1">
					<text class='fu-iconfont2  platformMessage_fd0_0_c0_c0'>&#xE794;</text>
				</view>
				<view class='flex flex-wrap align-stretch justify-center'>
					<text class='platformMessage_fd0_0_c1_c0' v-if="type == 1">核心一句-海马体1抗遗忘训练</text>
					<text class='platformMessage_fd0_0_c1_c0' v-if="type == 2">核心一句-海马体2抗遗忘训练</text>
				</view>
				<view class='flex flex-wrap align-center platformMessage_fd0_0_c0'></view>
			</view>

		</view>
		<view :style="{height: (64+StatusBarRpx)+'rpx'}"></view>
		<view class="loading_css" v-if="isShow">
			<uv-loading-icon size="24" mode="circle" color="#4087FD" :show="true"></uv-loading-icon>
			<view>加载中</view>
		</view>
		

		<view class="flex flex-direction align-stretch benben-flex-layout platformMessage_flex_1" v-else>
			<view class="intensify" v-for="(v, k) in list" :key="k" @tap.stop="goDetails(v.aid)">
				<view class="intensify_title">{{v.accompanylist_core_text}}</view>
				<view class="intensify_date">
					<text>{{v.create_time}}</text>
					<template v-if="type == 2">
						<text v-if="v.is_strengthen == 2" class="qianghua" @tap.stop="getAudio(v.aid)">待强化</text>
						<text v-if="v.is_strengthen == 1" class="qianghua_end" @tap.stop="enhanced">已完成</text>
					</template>
				</view>
			</view>
			<view class="loadmore" v-if="last_page > 1">
				<uv-load-more :status="status" :loading-text="loadingText" :loadmore-text="loadmoreText"
					:nomore-text="nomoreText" />
			</view>
		</view>
		<view class="noData" v-if="list.length == 0 && !isShow">
			<image :src='STATIC_URL+"no.png"'></image>
		</view>
		
		<uv-overlay :show="show">
			<view class="warp">
				<view class="rect">
					<view class="input_view" >
						<view class="input_title">{{record_data.day}}</view>
						<view class="input_content">
							{{record_data.core_text}}
						</view>
						<view class="input_img">
							<image v-if="!is_play" @tap.stop="playAudio" :src='STATIC_URL+"97.png"' mode="aspectFill"></image>
							<image v-if="is_play" :src='STATIC_URL+"96.png"' mode="aspectFill"></image>
						</view>
						<view class="input_bottom">
							<view class="input_bottom_1" @click="show = false">取消</view>
							<view class="input_bottom_2" @click="intensify">确认强化</view>
						</view>
					</view>
				</view>
			</view>
		</uv-overlay>
	</view>
</template>
<script>
	import {
		validate
	} from '@/common/utils/validate.js'
	export default {
		components: {},


		data() {
			return {
				show: false,
				"list": [],
				"page": 1,
				"is_pull": true,
				"last_page": 1,
				"status": 'loadmore',
				"loadingText": '努力加载中',
				"loadmoreText": '轻轻上拉',
				"nomoreText": '没有更多了',
				"isShow": true,
				
				"type": 1,  // 1海马体1  2海马体2
				"record_data": {
					"core_audio": {
						path: ""
					},
					"m_core_audio": {
						path: ""
					}
				},
				"is_play": false,
				"innerAudioContext": null,
				"languageType": 1,
				"record_id": "",
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {
			let {type} = options;
			if (type !== undefined) this.type = type;
			
		},
		onUnload() {

		},
		onReady() {
			this.innerAudioContext = uni.createInnerAudioContext();
		},
		onShow() {
			this.languageType = uni.getStorageSync('languageType');
			this.page = 1;
			this.is_pull = true;
			this.isShow = true;
			this.getList();
		},
		onHide() {

		},
		onResize() {

		},
		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1;
			this.is_pull = true;
			this.isShow = true;
			this.getList();
		},
		// 上拉加载
		onReachBottom() {
			if (this.page >= this.last_page) return;
			this.status = 'loading';
			this.page++;
			setTimeout(() => {
		
				if (this.page >= this.last_page) this.status = 'nomore';
				else this.status = 'loading';
				this.is_pull = false;
				this.getList();
			}, 500)
		},
		onPageScroll(e) {

		},
		methods: {
			// 获取陪看海马体1  post656e931ff2ae9
			getList() {
				let url = ""
				if (this.type == 1) {
					url = global.apiUrls.post656e931ff2ae9;
				} else if (this.type == 2) {
					url = global.apiUrls.post656ec45b3f268;
				}
				this.$api.post(url, {
					page: this.page
				}).then(res => {
					// console.log(res);
					uni.stopPullDownRefresh();
					this.isShow = false;
					if (res.data.code == 1) {
						this.last_page = res.data.data.last_page;
						if (this.is_pull) {
							this.list = res.data.data.data;
						} else {
							this.list = this.list.concat(res.data.data.data);
						}
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},
			goDetails(aid) {
				if (this.type == 1) {
					uni.navigateTo({
						url: '/pages/index/antiForget/watchOneDetails?aid=' + aid
					})
				}
				
			},
			getAudio(aid) {
				this.record_id = aid;
				this.$api.post(global.apiUrls.post656ed10a9a520, {
					aid: aid
				}).then(res => {
					// console.log(res);
					if (res.data.code == 1) {
						this.record_data = res.data.data;
						this.show = true;
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},
			enhanced() {
				this.$message.info('已强化')
			},
			// 播放音频
			playAudio() {
				if (this.innerAudioContext) {
					this.innerAudioContext.destroy();
				}
				this.innerAudioContext = null;
				this.innerAudioContext = uni.createInnerAudioContext();
				this.innerAudioContext.autoplay = true;
				if (this.languageType == 1) {
					this.innerAudioContext.src = this.record_data.m_core_audio.path;
				} else {
					this.innerAudioContext.src = this.record_data.core_audio.path;
				}
				
				this.innerAudioContext.onPlay(() => {
					this.is_play = true;
					console.log('开始播放');
				});
				this.innerAudioContext.onError((res) => {
					console.log(res.errMsg);
					console.log(res.errCode);
					this.$message.info('播放失败，请稍后再试');
					this.is_play = false;
					this.$forceUpdate();
				});
				this.innerAudioContext.onEnded(() => {
					this.is_play = false;
					this.$forceUpdate();
				})
			},
			// 强化
			intensify(index) {
				this.show = false;
				this.$api.post(global.apiUrls.post656ed4a72f7bf, {
					aid: this.record_id
				}).then(res => {
					this.$message.info(res.data.msg);
					if (res.data.code == 1) {
						this.getList();
					}
				})
			},
		}
	};
</script>
<style lang="scss" scoped>
	.warp {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 100%;
	}
	
	.rect {
		width: 450rpx;
		height: 400rpx;
		border-radius: 10rpx;
		background-color: #fff;
		text-align: center;
		position: relative;
	}
	.audio_img {
		width: 94rpx;
		height: 94rpx;
		margin: 55rpx auto 0;
	}
	.audio_text {
		font-size: 25rpx;
		color: #333333;
		margin-top: 25rpx;
	}
	.input_view {
		padding: 28rpx 0 0 0;
		.input_title {
			font-size: 28rpx;
			font-weight: 500;
		}
		.input_content {
			margin: 25rpx 0 0 0;
			padding: 0 25rpx;
			line-height: 38rpx;
		}
		.input_img {
			width: 94rpx;
			height: 94rpx;
			margin: 25rpx auto 0;
			image {
				width: 100%;
				height: 100%;
			}
		}
		.input_bottom {
			position: absolute;
			bottom: 0;
			left: 0;
			width: 100%;
			border-top: 1px solid #dddddd;
			padding: 20rpx;
			display: flex;
			justify-content: space-between;
			.input_bottom_1 {
				width: 50%;
				text-align: center;
				font-size: 25rpx;
				color: #999999;
			}
			.input_bottom_2 {
				width: 50%;
				text-align: center;
				font-size: 25rpx;
				color: #4087FD;
			}
		}
	}
	
	.intensify {
		margin: 15rpx 0 0;
		background: #fff;
		border-radius: 10rpx;
		padding: 20rpx;
		.intensify_title {
			display: flex;
			align-items: center;
			font-size: 20rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #333333;
		}
		.intensify_date {
			font-size: 18rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #999999;
			margin-top: 10rpx;
			display: flex;
			justify-content: space-between;
			.qianghua {
				color: #FA3B3D;
			}
			.qianghua_end {
				color: #4DC777;
			}
		}
	}
	
	.content_img {
		width: 100%;
		height: 219rpx;
		margin-top: 20rpx;
		image {
			width: 100%;
			height: 100%;
			border-radius: 10rpx;
		}
	}
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: rgba(248, 248, 248, 1);
		background-size: 100% auto !important;
	}

	.platformMessage_flex_0 {
		background: #fff;
		width: 100%;
		height: 64rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.platformMessage_fd0_0_c1_c0 {
		font-size: 25rpx;
		font-weight: 500;
		color: #333333;
		line-height: 64rpx;
	}

	.platformMessage_fd0_0_c0_c0 {
		font-size: 25rpx;
		color: #333;
	}

	.platformMessage_fd0_0_c0 {
		width: 50rpx;
		height: 50rpx;
	}

	.platformMessage_fd0_0 {
		padding: 0rpx 25rpx 0rpx 25rpx;
	}

	.platformMessage_flex_1 {
		// margin: 16rpx 25rpx 16rpx 25rpx;
		// background: #fff;
		// border-radius: 10rpx;
		padding: 0 25rpx;
	}

	.platformMessage_fd1_0_c2 {
		font-size: 18rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		color: #999999;
		line-height: 25rpx;
	}

	.platformMessage_fd1_0_c1 {
		margin: 10rpx 0rpx 0rpx 0rpx;
		font-size: 18rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		color: #999999;
		line-height: 26rpx;
		// -webkit-line-clamp: 2;
		// overflow: hidden;
		// text-overflow: ellipsis;
		// display: -webkit-box;
		// -webkit-box-orient: vertical;
	}

	.platformMessage_fd1_0_c0 {
		font-size: 20rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		color: #333333;
		// line-height: 45rpx;
		// -webkit-line-clamp: 1;
		// overflow: hidden;
		// text-overflow: ellipsis;
		// display: -webkit-box;
		// -webkit-box-orient: vertical;
	}

	.platformMessage_fd1_0 {
		// background: #fff;
		width: 100%;
		padding: 20rpx 25rpx 20rpx 25rpx;
		border-bottom: 1px solid #eee;
	}
</style>